package com.liuzh.deviceinfo.view.circleprogress;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.MeasureSpec;
import c.h.a.m0.h;
import c.h.a.q;

public class ArcProgress extends View {
    public Paint a;
    public Paint b;
    public RectF c = new RectF();
    public float d;
    public float e;
    public float f;
    public String g;
    public float h;
    public int i;
    public int j = 0;
    public int k;
    public int l;
    public int m;
    public float n;
    public String o;
    public float p;
    public float q;
    public final int r;
    public final int s;
    public final float t;
    public final float u;
    public final float v;
    public final float w;
    public final String x;
    public float y;
    public final int z;

    public ArcProgress(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0);
        String str = "%";
        this.o = str;
        int rgb = Color.rgb(72, 106, 176);
        this.r = rgb;
        int rgb2 = Color.rgb(66, 145, 241);
        this.s = rgb2;
        this.y = (float) h.u(18.0f, getResources().getDisplayMetrics());
        this.z = h.t(100.0f, getResources().getDisplayMetrics());
        this.y = (float) h.u(40.0f, getResources().getDisplayMetrics());
        float u = (float) h.u(15.0f, getResources().getDisplayMetrics());
        this.t = u;
        float t = (float) h.t(4.0f, getResources().getDisplayMetrics());
        this.u = t;
        this.x = str;
        float u2 = (float) h.u(10.0f, getResources().getDisplayMetrics());
        this.v = u2;
        float t2 = (float) h.t(4.0f, getResources().getDisplayMetrics());
        this.w = t2;
        TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(attributeSet, q.a, 0, 0);
        this.l = obtainStyledAttributes.getColor(3, -1);
        this.m = obtainStyledAttributes.getColor(12, rgb);
        this.i = obtainStyledAttributes.getColor(10, rgb2);
        this.h = obtainStyledAttributes.getDimension(11, this.y);
        this.n = obtainStyledAttributes.getFloat(0, 288.0f);
        setMax(obtainStyledAttributes.getInt(4, 100));
        setProgress(obtainStyledAttributes.getInt(5, 0));
        this.d = obtainStyledAttributes.getDimension(6, t2);
        this.e = obtainStyledAttributes.getDimension(9, u);
        if (!TextUtils.isEmpty(obtainStyledAttributes.getString(7))) {
            str = obtainStyledAttributes.getString(7);
        }
        this.o = str;
        this.p = obtainStyledAttributes.getDimension(8, t);
        this.f = obtainStyledAttributes.getDimension(2, u2);
        this.g = obtainStyledAttributes.getString(1);
        obtainStyledAttributes.recycle();
        a();
    }

    public void a() {
        TextPaint textPaint = new TextPaint();
        this.b = textPaint;
        textPaint.setColor(this.i);
        this.b.setTextSize(this.h);
        this.b.setAntiAlias(true);
        Paint paint = new Paint();
        this.a = paint;
        paint.setColor(this.r);
        this.a.setAntiAlias(true);
        this.a.setStrokeWidth(this.d);
        this.a.setStyle(Style.STROKE);
        this.a.setStrokeCap(Cap.ROUND);
    }

    public float getArcAngle() {
        return this.n;
    }

    public String getBottomText() {
        return this.g;
    }

    public float getBottomTextSize() {
        return this.f;
    }

    public int getFinishedStrokeColor() {
        return this.l;
    }

    public int getMax() {
        return this.k;
    }

    public int getProgress() {
        return this.j;
    }

    public float getStrokeWidth() {
        return this.d;
    }

    public String getSuffixText() {
        return this.o;
    }

    public float getSuffixTextPadding() {
        return this.p;
    }

    public float getSuffixTextSize() {
        return this.e;
    }

    public int getSuggestedMinimumHeight() {
        return this.z;
    }

    public int getSuggestedMinimumWidth() {
        return this.z;
    }

    public int getTextColor() {
        return this.i;
    }

    public float getTextSize() {
        return this.h;
    }

    public int getUnfinishedStrokeColor() {
        return this.m;
    }

    public void invalidate() {
        a();
        super.invalidate();
    }

    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        float f = 270.0f - (this.n / 2.0f);
        float max = (((float) this.j) / ((float) getMax())) * this.n;
        float f2 = this.j == 0 ? 0.01f : f;
        this.a.setColor(this.m);
        canvas.drawArc(this.c, f, this.n, false, this.a);
        this.a.setColor(this.l);
        canvas.drawArc(this.c, f2, max, false, this.a);
        String valueOf = String.valueOf(getProgress());
        if (!TextUtils.isEmpty(valueOf)) {
            this.b.setColor(this.i);
            this.b.setTextSize(this.h);
            float ascent = this.b.ascent() + this.b.descent();
            float height = (((float) getHeight()) - ascent) / 2.0f;
            canvas.drawText(valueOf, (((float) getWidth()) - this.b.measureText(valueOf)) / 2.0f, height, this.b);
            this.b.setTextSize(this.e);
            canvas.drawText(this.o, (this.b.measureText(valueOf) + (((float) getWidth()) / 2.0f)) + this.p, (height + ascent) - (this.b.ascent() + this.b.descent()), this.b);
        }
        if (this.q == 0.0f) {
            this.q = (((float) getWidth()) / 2.0f) * ((float) (1.0d - Math.cos(((double) (((360.0f - this.n) / 2.0f) / 180.0f)) * 3.141592653589793d)));
        }
        if (!TextUtils.isEmpty(getBottomText())) {
            this.b.setTextSize(this.f);
            canvas.drawText(getBottomText(), (((float) getWidth()) - this.b.measureText(getBottomText())) / 2.0f, (((float) getHeight()) - this.q) - ((this.b.ascent() + this.b.descent()) / 2.0f), this.b);
        }
    }

    public void onMeasure(int i, int i2) {
        setMeasuredDimension(i, i2);
        i = MeasureSpec.getSize(i);
        RectF rectF = this.c;
        float f = this.d;
        float f2 = (float) i;
        rectF.set(f / 2.0f, f / 2.0f, f2 - (f / 2.0f), ((float) MeasureSpec.getSize(i2)) - (this.d / 2.0f));
        this.q = (f2 / 2.0f) * ((float) (1.0d - Math.cos(((double) (((360.0f - this.n) / 2.0f) / 180.0f)) * 3.141592653589793d)));
    }

    public void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof Bundle) {
            Bundle bundle = (Bundle) parcelable;
            this.d = bundle.getFloat("stroke_width");
            this.e = bundle.getFloat("suffix_text_size");
            this.p = bundle.getFloat("suffix_text_padding");
            this.f = bundle.getFloat("bottom_text_size");
            this.g = bundle.getString("bottom_text");
            this.h = bundle.getFloat("text_size");
            this.i = bundle.getInt("text_color");
            setMax(bundle.getInt("max"));
            setProgress(bundle.getInt("progress"));
            this.l = bundle.getInt("finished_stroke_color");
            this.m = bundle.getInt("unfinished_stroke_color");
            this.o = bundle.getString("suffix");
            a();
            super.onRestoreInstanceState(bundle.getParcelable("saved_instance"));
            return;
        }
        super.onRestoreInstanceState(parcelable);
    }

    public Parcelable onSaveInstanceState() {
        Bundle bundle = new Bundle();
        bundle.putParcelable("saved_instance", super.onSaveInstanceState());
        bundle.putFloat("stroke_width", getStrokeWidth());
        bundle.putFloat("suffix_text_size", getSuffixTextSize());
        bundle.putFloat("suffix_text_padding", getSuffixTextPadding());
        bundle.putFloat("bottom_text_size", getBottomTextSize());
        bundle.putString("bottom_text", getBottomText());
        bundle.putFloat("text_size", getTextSize());
        bundle.putInt("text_color", getTextColor());
        bundle.putInt("progress", getProgress());
        bundle.putInt("max", getMax());
        bundle.putInt("finished_stroke_color", getFinishedStrokeColor());
        bundle.putInt("unfinished_stroke_color", getUnfinishedStrokeColor());
        bundle.putFloat("arc_angle", getArcAngle());
        bundle.putString("suffix", getSuffixText());
        return bundle;
    }

    public void setArcAngle(float f) {
        this.n = f;
        invalidate();
    }

    public void setBottomText(String str) {
        this.g = str;
        invalidate();
    }

    public void setBottomTextSize(float f) {
        this.f = f;
        invalidate();
    }

    public void setFinishedStrokeColor(int i) {
        this.l = i;
        invalidate();
    }

    public void setMax(int i) {
        if (i > 0) {
            this.k = i;
            invalidate();
        }
    }

    public void setProgress(int i) {
        this.j = i;
        if (i > getMax()) {
            this.j %= getMax();
        }
        invalidate();
    }

    public void setStrokeWidth(float f) {
        this.d = f;
        invalidate();
    }

    public void setSuffixText(String str) {
        this.o = str;
        invalidate();
    }

    public void setSuffixTextPadding(float f) {
        this.p = f;
        invalidate();
    }

    public void setSuffixTextSize(float f) {
        this.e = f;
        invalidate();
    }

    public void setTextColor(int i) {
        this.i = i;
        invalidate();
    }

    public void setTextSize(float f) {
        this.h = f;
        invalidate();
    }

    public void setUnfinishedStrokeColor(int i) {
        this.m = i;
        invalidate();
    }
}
